#ifndef FILEDIALOG_H
#define FILEDIALOG_H

#include <QFileDialog>
#include <QSortFilterProxyModel>
#include <QFileSystemModel>
#include <QString>
#include <QFlags>
#include <QByteArray>
#include <QSettings>


//------------------------------------
//------------ProxyModel--------------
//------------------------------------

class ProxyModel : public QSortFilterProxyModel
{
		Q_OBJECT

	private:
		bool m_saveMode;
		QFileSystemModel *  m_fsModel;

	public:
		ProxyModel (QObject * parent, bool saveMode);
		Qt::ItemFlags flags (const QModelIndex & index) const;
		bool lessThan ( const QModelIndex & left, const QModelIndex & right ) const;
};

//------------------------------------
//------------FileDialog--------------
//------------------------------------

class FileDialog : public QFileDialog
{
		Q_OBJECT

	private:

		QSettings* m_settings;

	public:
		explicit FileDialog(QWidget *parent = 0) : QFileDialog (parent, Qt::Dialog)
		{
			QFileDialog::setAcceptMode (QFileDialog::AcceptOpen);
			m_settings = new QSettings ("PapaJaac", "fileDialog", this);
			restoreState (m_settings->value ("state", QVariant ()).toByteArray());
		}

		~FileDialog ()
		{
			m_settings->setValue("state", saveState());
			delete m_settings;
		}

		void setAcceptMode (QFileDialog::AcceptMode mode)
		{
			setProxyModel (new ProxyModel (this, mode == QFileDialog::AcceptSave));

			QFileDialog::setAcceptMode (mode);
		}

		static QString getSaveFileName (QWidget * parent = 0,
										const QString & caption = QString (),
										const QString & dir = QString (),
										const QString & filter = QString (),
										QString * selectedFilter = 0,
										Options options = 0,
										const QString& defaultSuffix = QString ());

		static QString getOpenFileName (QWidget * parent = 0,
										const QString & caption = QString (),
										const QString & dir = QString (),
										const QString & filter = QString (),
										QString * selectedFilter = 0,
										Options options = 0,
										const QString& defaultSuffix = QString ());

		static QStringList getOpenFileNames (QWidget * parent = 0,
											 const QString & caption = QString (),
											 const QString & dir = QString (),
											 const QString & filter = QString (),
											 QString * selectedFilter = 0,
											 Options options = 0,
											 const QString& defaultSuffix = QString ());

	signals:

	public slots:

};

#endif // FILEDIALOG_H
